
const checkDomain = (rule, value, callback) => {
  if (!value) {
    callback(new Error("请输入域名"));
  } else {
    if([...new Set(value.split('\n'))].length !== value.split('\n').length){
      return callback(new Error("域名重复"));
    }
    for (let item of value.split('\n')) {
      var strTemp = /^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$/;
      if (!strTemp.test(item)) {
        return callback(new Error("域名不符合规则"));
      }
    }
    callback();
  }
};

export const tableOption = {
  border: true,
  stripe: true,
  menuAlign: 'center',
  align: 'center',
  searchMenuSpan: 6,
  viewBtn: false,
  addBtn: true,
  editBtn: false,
  delBtn: false,
  column: [{
    label: '创建时间',
    searchType: 'datetimerange',
    searchSpan: 10,
    search: true,
    addDisplay: false,
    editDisplay: false,
    span: 24,
    prop: 'create_time',
  }, {
    label: '域名',
    prop: 'domain',
    type:'textarea',
    span: 24,
    rules: [{
      required: true,
      validator: checkDomain,
      trigger: "blur"
    }]
  },{
    label: '订单号',
    search: true,
    addDisplay: false,
    editDisplay: false,
    span: 24,
    prop: 'order_no',
  },{
    label: '价格',
    prop: 'price_search',
    type: "select",
    span: 24,
    hide: true,
    dicFlag: true,
    addDisplay: false,
    editDisplay: false,
    searchFilterable: true,
    search: true,
    dicUrl: process.env.VUE_APP_BASE_API + "/admin/dict/find?type=order_money",
    dicFormatter: res => {
      return (res.data || []).map(o => ({
        label: o.label,
        value: o.value
      }));
    },
    props: {
      label: "label",
      value: "value"
    },
    rules: [{
      required: true,
      message: "请输入"
    }],
  }, {
    label: '售价',
    prop: 'price',
    span: 24,
    rules: [{
      required: true,
      message: "请输入"
    }],
  }, {
    label: '回购价',
    span: 24,
    rules: [{
      required: true,
      message: "请输入"
    }],
    prop: 'price_back'
  },{
    label: '回购周期',
    type:'number',
    span: 24,
    rules: [{
      required: true,
      message: "请输入"
    }],
    prop: 'days'
  },
  // {
  //   label: '用户',
  //   prop: 'user_id',
  //   type: "select",
  //   span: 24,
  //   hide: true,
  //   filterable: true,
  //   dicFlag: true,
  //   dicUrl: process.env.VUE_APP_BASE_API + "/admin/user/listAll",
  //   dicFormatter: res => {
  //     return (res.data || []).map(o => ({
  //       label: o.name,
  //       value: o.id
  //     }));
  //   },
  //   props: {
  //     label: "label",
  //     value: "value"
  //   },
  //   rules: [{
  //     required: true,
  //     message: "请输入"
  //   }],
  // }, {
  //   label: '卖家',
  //   search: true,
  //   addDisplay: false,
  //   editDisplay: false,
  //   span: 24,
  //   prop: 'name'
  // },
  // {
  //   label: '收款方式',
  //   hide: true,
  //   span: 24,
  //   prop: 'method',
  //   type: "radio",
  //   dicData: [{
  //     label: '支付宝',
  //     value: 1
  //   }, {
  //     label: '微信',
  //     value: 2
  //   }],
  //   rules: [{
  //     required: true,
  //     message: "请输入"
  //   }],
  // },
  {
    label: '交易描述',
    hide: true,
    span: 24,
    prop: 'des',
    type: 'textarea'
  },{
    label: '上架/下架',
    prop: 'type',
    span: 24,
    addDisplay: false,
    editDisplay: false,
    slot: true,
  },  {
    label: '订单状态',
    prop: 'status',
    type: "radio",
    addDisplay: false,
    editDisplay: false,
    search: true,
    span: 24,
    dicUrl: process.env.VUE_APP_BASE_API + "/api/status",
    dicFormatter: res => {
      return (res.data || []).map(o => ({
        label: o.label,
        value: o.value
      }));
    },
  }]
}
